<template>
	<cu-editor ref="editor" :showFixTopBar="false" :url="uploadUrl" :content="content"
		@hideToolbar="handleSubmit"></cu-editor>
</template>

<script>
	import baseConfig from '@/config/baseUrl.js'
	import cuEditor from '@/components/cu-editor/cu-editor'
	import {
		handleHtmlImage
	} from '@/components/cu-editor/util'
	export default {
		components: {
			cuEditor
		},
		data() {
			return {
				content: '',
				uploadUrl: baseConfig.uploadUrl + '/sys/common/upload',
			}
		},
		onLoad() {
			let content = uni.getStorageSync('activeContent')
			if (content && content.length > 0) {
				this.content = content
			}
		},
		onUnload() {
			this.saveContent() //返回时保存
		},
		methods: {
			async saveContent() {
				let tContent = await this.getRichText()
			},
			handleSubmit(e) {
				uni.setStorageSync('activeContent', e)
				setTimeout(() => {
					uni.navigateBack()
				}, 1000)
			},
			getRichText() {
				const that = this
				return new Promise((resolve, reject) => {
					that.$refs.editor.getContents(res => {
						res.html = handleHtmlImage(res.html)
						resolve(res.html)
					})
				})
			},
		}
	}
</script>

<style>
</style>